Page({
    data: {
        balance: '1,248.50',
        points: '3,850',
        showModal: false, // 控制弹框显示隐藏

        members: [
            {
              avatar: "https://ts2.tc.mm.bing.net/th/id/OIP-C.GUh4_2KUPP3O5zjTiuhk7gAAAA?cb=thfvnext&rs=1&pid=ImgDetMain&o=7&rm=3",
              name: "张先生",
              role: "管理员"
            },
            {
              avatar: "https://ts3.tc.mm.bing.net/th/id/OIP-C.tpOs1kFtRNfu6pzkNl1auQHaHa?cb=thfvnext&rs=1&pid=ImgDetMain&o=7&rm=3",
              name: "李女士",
              role: "成员"
            },
            {
              avatar: "https://img.51miz.com/preview/element/00/01/16/05/E-1160573-96F1261D.jpg",
              name: "张小宝",
              role: "成员"
            }
          ],
          showAddModal: false,
          nickname: "",
          role: "管理员" // 默认选择管理员，可根据需求调整
    },
  
    // 显示积分规则弹框
    showPointsRuleModal() {
      this.setData({
        showModal: true
      });
    },
  
    // 隐藏积分规则弹框
    hidePointsRuleModal() {
      this.setData({
        showModal: false
      });
    },

    // 显示添加成员弹框
  showAddMemberModal() {
    this.setData({
      showAddModal: true
    });
  },

  // 隐藏添加成员弹框
  hideAddMemberModal() {
    this.setData({
      showAddModal: false,
      nickname: "",
      role: "管理员" // 重置表单数据
    });
  },

  // 输入成员昵称事件
  onNicknameInput(e) {
    this.setData({
      nickname: e.detail.value
    });
  },

  // 选择成员权限事件
  onRoleChange(e) {
    this.setData({
      role: e.detail.value
    });
  },

  // 确认添加成员
  confirmAddMember() {
    if (!this.data.nickname.trim()) {
      wx.showToast({
        title: "请输入成员昵称",
        icon: "none"
      });
      return;
    }
    // 这里可调用接口将新成员信息提交到服务器，示例仅做前端模拟添加
    const newMember = {
      avatar: "/images/default-avatar.png", // 可替换为实际默认头像或用户选择的头像
      name: this.data.nickname,
      role: this.data.role === "管理员" ? "管理员" : "成员"
    };
    this.data.members.push(newMember);
    this.setData({
      members: this.data.members,
      showAddModal: false,
      nickname: "",
      role: "管理员"
    });
    wx.showToast({
      title: "添加成功",
      icon: "success"
    });
  }
  });